package com.jingdianjichi.subject.infra.rpc;


import com.jingdianjichi.auth.api.UserFeignService;
import com.jingdianjichi.auth.entity.AuthUserDTO;
import com.jingdianjichi.auth.entity.Result;
import com.jingdianjichi.subject.infra.entity.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;


/**
 * @Description:  调用auth微服务提供的Feign接口，实现跨微服务的功能调用
 *              即：建立一个FeignClient客户端
 *              服务端、客户端是通过nacos进行相互发现的  @FeignClient("jc-club-auth")
 * @return:
 * @Author:  sky
 * @date:  2024/11/24 20:03
 */
@Component
public class UserRpc {

    @Resource
    private UserFeignService userFeignService;


    public UserInfo getUserInfo(String userName){
        AuthUserDTO authUserDTO = new AuthUserDTO();
        authUserDTO.setUserName(userName);
        Result<AuthUserDTO> result = userFeignService.getUserInfo(authUserDTO);
        UserInfo userInfo = new UserInfo();
        // 查询成功
        if(result.getSuccess()){
            AuthUserDTO data = result.getData();
            userInfo.setUserName(data.getUserName());
            userInfo.setNickName(data.getNickName());
        }
        // 查询失败
        return userInfo;
    }
}
